/*
 *  @author  Alpesh Mistry  <apm1dec@gmail.com>
 *  @author  Ankur Kothari  <a.kothari711@gmail.com>
 *  @author  Elman Mansimov <elman.mansimov@gmail.com>
 *  @author  Michelle Pan   <panmiche@gmail.com>
 *  @version 1.0
 *  @since   2012-03-03
 */

public class File extends SystemItem {
	
	private String contents;
	
	/**
	 * Initialize a File object with a name, parent directory
	 * and set its contents to an empty string.
	 * @param n String which is the name of File
	 * @param dir Directory which is the parent of Directory
	 */
	public File(String n, Directory dir) {
		super(n, dir);
		setContents("");
	}
	
	/**
	 * Return contents of File.
	 * @return String which is contents of File.
	 */
	public String getContents() {
		return contents;
	}
	
	/**
	 * Set contents of File.
	 * @param text String which is contents of File
	 */
	public void setContents(String text) {
		contents = text;
	}
	
	/**
	 * Reset contents of File to an empty string.
	 */
	public void eraseContents() {
		this.setContents("");
	}
	
	/**
	 * Append text to contents of File after adding a new line.
	 * If File is empty make text to be new contents of it.
	 * @param text String which will be added to contents of File
	 */
	public void appendContents(String text) {
		if (contents.equals("")){
			contents = text;
		}else{
			contents = contents + "\n" + text;
		}
	}
	
	/**
	 * Print contents of File to the screen.
	 */
	public void printContents() {
		System.out.println(getContents());
	}
}